<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="企业名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="成立时间" >
        <el-date-picker clearable
                        v-model="queryParams.foundingDate"
                        value-format="yyyy-MM-dd"
                        type="date"
                        placeholder="请选择成立时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="注册资本" prop="name">
        <el-input
          v-model="queryParams.registeredCapital"
          placeholder="请输入注册资本"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="登记状态" prop="status">

        <el-select v-model="queryParams.status" filterable clearable placeholder="请选择登记状态">
          <el-option
            v-for="item in statusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>

<!--      <el-form-item label="所属地区" prop="areaId">-->
<!--        <el-cascader-->
<!--          v-model="queryParams.areaIds"-->
<!--          placeholder="请选择所属地区"-->
<!--          :options="areaOptions"-->
<!--          :props="{ value: 'id',checkStrictly: true}"-->
<!--          filterable></el-cascader>-->
<!--      </el-form-item>-->
      <el-form-item label="所属地区" prop="areaId">
        <el-cascader
          v-model="queryParams.parkAreaId"
          placeholder="请选择所属地区"
          :options="parkAreaOptions"
          :props="{ value: 'id',checkStrictly: true,emitPath:false}"
          filterable
          clearable
        ></el-cascader>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['company:company:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleUploadAdd"
        >上传企查查企业文件
        </el-button>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="companyList" @selection-change="handleSelectionChange">
      <el-table-column label="企业名称" align="center" prop="name"/>
      <el-table-column label="成立时间" align="center" prop="foundingDate"/>
      <el-table-column label="注册资本" align="center" prop="registeredCapital"/>
      <el-table-column label="登记状态" align="center" prop="status"/>
<!--      <el-table-column label="行政区域" align="center" prop="areaName"/>-->
      <el-table-column label="所属地区" align="center" prop="parkAreaName"/>
      <el-table-column label="编辑人员" align="center" prop="updateName"/>
      <el-table-column label="编辑时间" align="center" prop="updateTime"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="getPatentList(scope.row)"
          >专利信息
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="getAccsList(scope.row)"
          >软件著作权信息
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['company:company:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['company:company:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改公司对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1500px" :close-on-click-modal="false" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">

        <el-row>
          <el-col :span="12">
            <el-form-item label="企业名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入企业名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="登记状态" prop="quota">
              <el-select v-model="form.status" filterable clearable placeholder="请选择登记状态">
                <el-option
                  v-for="item in statusOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value+''"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="曾用名" prop="historyName">
              <el-input v-model="form.historyName" placeholder="请输入曾用名"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">

          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="法定代表人" prop="founder">
              <el-input v-model="form.founder" placeholder="请输入法定代表人"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="成立时间" prop="foundingDate">
              <el-input v-model="form.foundingDate" placeholder="请输入成立时间"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="统一社会信用代码" prop="identifier">
              <el-input v-model="form.identifier" placeholder="请输入统一社会信用代码"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="注册资本" prop="registeredCapital">
              <el-input style="width: 150px;" v-model="form.registeredCapital" placeholder="请输入注册资本"/>
              <el-select style="width: 120px;" v-model="form.currency" placeholder="请选择币种">
                <el-option
                  v-for="dict in dict.type.currency"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="实缴资本" prop="outCapital">
              <el-input style="width: 150px;" v-model="form.outCapital" placeholder="请输入实缴资本"/>
              <el-select style="width: 120px;" v-model="form.outCurrency" placeholder="请选择币种">
                <el-option
                  v-for="dict in dict.type.currency"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="参保人数" prop="cbrs">
              <el-input v-model="form.cbrs" placeholder="请输入参保人数"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
<!--          <el-col :span="8">-->
<!--            <el-form-item label="所属地区" prop="areaId">-->
<!--              <el-cascader-->
<!--                v-model="form.areaIds"-->
<!--                placeholder="请选择所属地区"-->
<!--                :options="areaOptions"-->
<!--                :props="{ value: 'id',checkStrictly: true}"-->
<!--                filterable></el-cascader>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
          <el-col :span="8">
            <el-form-item label="所属地区" prop="parkAreaIds">

              <el-cascader
                v-model="form.parkAreaIds"
                placeholder="请选择所属地区"
                :options="parkAreaOptions"
                :props="{ value: 'id',checkStrictly: true}"
                filterable></el-cascader>
            </el-form-item>

          </el-col>
          <el-col :span="8">
            <el-form-item label="登记机关" prop="registrationAuthority">
              <el-input v-model="form.registrationAuthority" placeholder="请输入登记机关"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="所属行业" prop="industryId">
          <el-cascader
            v-model="form.industryIds"
            placeholder="请选择所属行业"
            :options="industryTreeOptions"
            :props="{ value: 'id',checkStrictly: true}"
            filterable></el-cascader>
        </el-form-item>

        <el-form-item label="注册地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入注册地址"/>
        </el-form-item>

        <el-form-item label="经营范围" prop="makesOffer">
          <el-input v-model="form.makesOffer" type="textarea" placeholder="请输入内容"/>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 专利信息列表对话框 -->
    <el-dialog :title="title" :visible.sync="patentListOpen" width="1500px" append-to-body>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handlePatentAdd"
          >新增
          </el-button>
        </el-col>
      </el-row>
      <el-table :data="companyPatentList">
        <el-table-column label="序号" align="center" prop="no"/>
        <el-table-column label="专利名称" align="center" prop="name"/>
        <el-table-column label="专利类型" align="center" prop="type"/>
        <el-table-column label="申请号" align="center" prop="applyNo"/>
        <el-table-column label="申请日期" align="center" prop="applyTime"/>
        <el-table-column label="公开(公告)日期" align="center" prop="openTime"/>
        <el-table-column label="法律状态" align="center" prop="status"/>
        <el-table-column label="发明人" align="center" prop="inventor"/>
        <el-table-column label="公开(公告)号" align="center" prop="openNo"/>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">

            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handlePatentUpdate(scope.row)"
            >修改
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handlePatentDelete(scope.row)"
            >删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 添加或修改公司专利信息对话框 -->
    <el-dialog :title="title" :visible.sync="patentOpen" width="1500px" append-to-body>
      <el-form ref="patentForm" :model="patentForm" :patentRules="patentRules" label-width="150px">

        <el-row>
          <el-col :span="12">
            <el-form-item label="专利名称" prop="patentName">
              <el-input v-model="patentForm.name" placeholder="请输入专利名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="专利类型" prop="type">
              <el-input v-model="patentForm.type" placeholder="请输入专利类型"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="申请号" prop="applyNo">
              <el-input v-model="patentForm.applyNo" placeholder="请输入申请号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请日期" prop="applyTime">
              <el-date-picker clearable
                              v-model="patentForm.applyTime"
                              type="date"
                              placeholder="请输入申请日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="公开(公告)日期" prop="openTime">
              <el-date-picker clearable
                              v-model="patentForm.openTime"
                              type="date"
                              placeholder="请输入公开(公告)日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法律状态" prop="status">
              <el-input v-model="patentForm.status" placeholder="请输入法律状态"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="发明人" prop="inventor">
              <el-input v-model="patentForm.inventor" placeholder="请输入发明人"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公开(公告)号" prop="openNo">
              <el-input v-model="patentForm.openNo" placeholder="请输入公开(公告)号"/>
            </el-form-item>
          </el-col>
        </el-row>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitPatentForm">确 定</el-button>
        <el-button @click="cancelPatent">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 软件著作权列表对话框 -->
    <el-dialog :title="title" :visible.sync="accsListOpen" width="1500px" append-to-body>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAccsAdd"
          >新增
          </el-button>
        </el-col>
      </el-row>
      <el-table :data="companyAccsList">
        <el-table-column label="序号" align="center" prop="no"/>
        <el-table-column label="软件全称" align="center" prop="name"/>
        <el-table-column label="版本号" align="center" prop="version"/>
        <el-table-column label="登记号" align="center" prop="registerNo"/>
        <el-table-column label="开发完成日期" align="center" prop="completeDate"/>
        <el-table-column label="登记日期" align="center" prop="registerDate"/>
        <el-table-column label="权利取得方式" align="center" prop="accessMode"/>
        <el-table-column label="软件简称" align="center" prop="shortName"/>
        <el-table-column label="首次发布日期" align="center" prop="publishDate"/>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">

            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleAccsUpdate(scope.row)"
            >修改
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleAccsDelete(scope.row)"
            >删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 添加或修改公司软件著作权对话框 -->
    <el-dialog :title="title" :visible.sync="accsOpen" width="1500px" append-to-body>
      <el-form ref="accsForm" :model="accsForm" :accsRules="accsRules" label-width="150px">

        <el-row>
          <el-col :span="12">
            <el-form-item label="软件全称" prop="accsName">
              <el-input v-model="accsForm.name" placeholder="请输入软件全称"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="版本号" prop="version">
              <el-input v-model="accsForm.version" placeholder="请输入版本号"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="登记号" prop="registerNo">
              <el-input v-model="accsForm.registerNo" placeholder="请输入登记号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开发完成日期" prop="completeDate">
              <el-date-picker clearable
                              v-model="accsForm.completeDate"
                              type="date"
                              placeholder="请输入开发完成日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="登记日期" prop="registerDate">
              <el-date-picker clearable
                              v-model="accsForm.registerDate"
                              type="date"
                              placeholder="请输入登记日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="权利取得方式" prop="accessMode">
              <el-input v-model="accsForm.accessMode" placeholder="请输入权利取得方式"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="软件简称" prop="shortName">
              <el-input v-model="accsForm.shortName" placeholder="请输入软件简称"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="首次发布日期" prop="publishDate">
              <el-date-picker clearable
                              v-model="accsForm.publishDate"
                              type="date"
                              placeholder="请输入首次发布日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitAccsForm">确 定</el-button>
        <el-button @click="cancelAccs">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改excel记录对话框 -->
    <el-dialog :title="title" :visible.sync="uploadOpen" width="1500px" append-to-body>
      <el-form ref="form" :model="uploadForm" :rules="rules" label-width="80px">
        <el-form-item label="文件导入" prop="attachments">
          <el-upload
            ref="upload"
            :limit="1"
            accept=".xlsx, .xls"
            :headers="upload.headers"
            :action="upload.url"
            :disabled="upload.isUploading"
            :on-progress="handleFileUploadProgress"
            :on-success="handleFileSuccess"
            :auto-upload="false"
            drag
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listCompany,
  getCompany,
  delCompany,
  addCompany,
  updateCompany,
  listCompanyPatent,
  getCompanyPatent,
  updateCompanyPatent,
  addCompanyPatent,
  updateCompanyAccs,
  addCompanyAccs,
  delCompanyPatent,
  delCompanyAccs, listCompanyAccs, getCompanyAccs
} from "@/api/company/company";
import {areaTree, tagSelect} from "@/api/org/org";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {parkAreaTree} from "@/api/area/parkArea";
import {industryTree} from "@/api/company/industry";
import {getToken} from "@/utils/auth";

export default {
  components: {Treeselect},
  name: "Company",
  dicts: ['profession_type', 'currency'],
  data() {
    return {
      // 遮罩层
      loading: true,
      props: {multiple: true},
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 公司表格数据
      companyList: [],
      // 公司专利信息表格数据
      companyPatentList: [],
      // 公司软件著作权表格数据
      companyAccsList: [],
      // 地区下拉列表
      areaOptions: [],
      // 园区下拉列表
      parkAreaOptions: [],
      // 行业下拉列表
      industryTreeOptions: [],
      // 状态下拉
      statusOptions: [{value: 1, label: '存续'}, {value: 2, label: '在业'}, {value: 3, label: '吊销'}
        , {value: 4, label: '注销'}, {value: 5, label: '迁入'}, {value: 6, label: '迁出'}, {value: 7, label: '停业'}
        , {value: 8, label: '清算'}],
      // 标签类型树
      tagTypeOptions: [],
      // 标签下拉项
      tagOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示上传弹出层
      uploadOpen: false,
      // 是否显示编辑专利信息弹出层
      patentOpen: false,
      // 是否显示编辑软件著作权弹出层
      accsOpen: false,
      patentListOpen: false,
      accsListOpen: false,
      companyId: null,
      // 查询参数
      queryParams: {
        createTimeStr: null,
        registeredCapital: null,
        status: null,
        areaIds: [],
        parkAreaIds: [],
        parkAreaId:'',
        pageNum: 1,
        pageSize: 10,
        name: null,
      },
      // 导入参数
      upload: {
        // 是否显示弹出层
        open: false,
        // 弹出层标题
        title: "企查查企业文件导入",
        // 是否禁用上传
        isUploading: false,
        updateSupport: 0,
        // 设置上传的请求头部
        headers: {Authorization: "Bearer " + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/company/company/importQccCompanyData"
      },
      // 表单参数
      form: {},
      uploadForm:{},
      patentForm: {},
      accsForm: {},
      // 表单校验
      rules: {
        name: [
          {required: true, message: "企业名称不能为空", trigger: "blur"}
        ],
      },
      // 表单校验
      patentRules: {
        patentName: [
          {required: true, message: "专利名称不能为空", trigger: "blur"}
        ],
      },
      // 表单校验
      accsRules: {
        accsName: [
          {required: true, message: "软件全称不能为空", trigger: "blur"}
        ],
      },
    };
  },
  created() {
    this.getList();
    this.areaTree();
    this.tagSelect();
    this.parkAreaTree();
    this.industryTree();
  },
  methods: {
    /** 查询公司列表 */
    getList() {
      this.loading = true;
      listCompany(this.queryParams).then(response => {
        this.companyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询公司专利信息列表 */
    getPatentList(row) {
      this.title = "专利信息";
      this.patentListOpen = true;
      this.companyId = row.id;
      listCompanyPatent(row.id).then(response => {
        this.companyPatentList = response.data;
      });
    },
    /** 查询公司软件著作权列表 */
    getAccsList(row) {
      this.title = "软件著作权";
      this.accsListOpen = true;
      this.companyId = row.id;
      listCompanyAccs(row.id).then(response => {
        this.companyAccsList = response.data;
      });
    },

    /** 查询地区列表 */
    areaTree() {
      areaTree().then(response => {
        this.areaOptions = response.data;
      });
    },
    /** 查询园区列表 */
    parkAreaTree() {
      parkAreaTree().then(response => {
        console.info(response.data);
        this.parkAreaOptions = response.data;
      });
    },
    /** 查询行业列表 */
    industryTree() {
      industryTree().then(response => {
        this.industryTreeOptions = response.data;
      });
    },
    tagSelect() {
      tagSelect().then(response => {
        this.tagOptions = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮
    cancelPatent() {
      this.patentOpen = false;
    },
    // 取消按钮
    cancelAccs() {
      this.accsOpen = false;
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        founder: null,
        registeredCapital: null,
        currency: null,
        outCapital: null,
        outCurrency: null,
        status: null,
        foundingDate: null,
        identifier: null,
        registrationNumber: null,
        organizationalCode: null,
        tin: null,
        enterpriseType: null,
        approvalDate: null,
        registrationAuthority: null,
        area: null,
        areaIds: [],
        parkAreaIds: [],
        englishName: null,
        historyName: null,
        timeCycleBegin: null,
        timeCycleEnd: null,
        cbrs: null,
        personnel: null,
        businessTerm: null,
        industry: null,
        industryIds: [],
        address: null,
        label: null,
        makesOffer: null,
        getApi: null,
        industryKeyword: null,
        baidu: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    // 表单重置
    resetPatentForm() {
      this.patentForm = {
        companyId: null,
        name: null,
        type: null,
        applyNo: null,
        applyTime: null,
        openTime: null,
        status: null,
        inventor: null,
        openNo: null,
      };
      this.resetForm("patentForm");
    },
    // 表单重置
    resetAccsForm() {
      this.accsForm = {
        companyId: null,
        name: null,
        version: null,
        registerNo: null,
        completeDate: null,
        registerDate: null,
        accessMode: null,
        shortName: null,
        publishDate: null,
      };
      this.resetForm("accsForm");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加公司";
    },
    /** 新增专利信息按钮操作 */
    handlePatentAdd() {
      this.resetPatentForm();
      this.patentOpen = true;
      this.title = "专利信息";
    },
    /** 新增专利信息按钮操作 */
    handleAccsAdd() {
      this.resetAccsForm();
      this.accsOpen = true;
      this.title = "软件著作权";
    },
    /** 上传文件按钮操作 */
    handleUploadAdd() {
      this.uploadOpen = true;
      this.title = "上传企查查企业文件";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCompany(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改公司";
      });
    },
    /** 修改专利信息按钮操作 */
    handlePatentUpdate(row) {
      this.resetPatentForm();
      const id = row.id
      getCompanyPatent(id).then(response => {
        this.patentForm = response.data;
        this.patentOpen = true;
        this.title = "专利信息";
      });
    },
    /** 修改软件著作权按钮操作 */
    handleAccsUpdate(row) {
      this.resetAccsForm();
      const id = row.id
      getCompanyAccs(id).then(response => {
        this.accsForm = response.data;
        this.accsOpen = true;
        this.title = "软件著作权信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCompany(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCompany(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 专利信息提交按钮 */
    submitPatentForm() {
      this.patentForm.companyId = this.companyId;
      this.$refs["patentForm"].validate(valid => {
        if (valid) {
          if (this.patentForm.id != null) {
            updateCompanyPatent(this.patentForm).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.patentOpen = false;
              listCompanyPatent(this.companyId).then(response => {
                this.companyPatentList = response.data;
              });
            });
          } else {
            addCompanyPatent(this.patentForm).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.patentOpen = false;
              listCompanyPatent(this.companyId).then(response => {
                this.companyPatentList = response.data;
              });
            });
          }
        }
      });
    },
    /** 软件著作权提交按钮 */
    submitAccsForm() {
      this.accsForm.companyId = this.companyId;
      this.$refs["accsForm"].validate(valid => {
        if (valid) {
          if (this.accsForm.id != null) {
            updateCompanyAccs(this.accsForm).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.accsOpen = false;
              listCompanyAccs(this.companyId).then(response => {
                this.companyAccsList = response.data;
              });
            });
          } else {
            addCompanyAccs(this.accsForm).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.accsOpen = false;
              listCompanyAccs(this.companyId).then(response => {
                this.companyAccsList = response.data;
              });
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除公司编号为"' + ids + '"的数据项？').then(function () {
        return delCompany(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 删除专利信息按钮操作 */
    handlePatentDelete(row) {
      const id = row.id;
      this.$modal.confirm('是否确认删除专利信息名称为"' + row.name + '"的数据项？').then(function () {
        return delCompanyPatent(id);
      }).then(() => {
        listCompanyPatent(this.companyId).then(response => {
          this.companyPatentList = response.data;
        });
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 删除软件著作权按钮操作 */
    handleAccsDelete(row) {
      const id = row.id;
      this.$modal.confirm('是否确认删除软件全称为"' + row.name + '"的数据项？').then(function () {
        return delCompanyAccs(id);
      }).then(() => {
        listCompanyAccs(this.companyId).then(response => {
          this.companyAccsList = response.data;
        });
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('company/company/export', {
        ...this.queryParams
      }, `company_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", {dangerouslyUseHTMLString: true});
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
